<template>
  <div>
    <!--  #####################查询条件###################  -->
    <div align="center" style="margin-bottom: 20px; font-size: 30px"><b>{{this.record.nickName}}</b></div>
    <!--  #####################查询条件###################  -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="领取状态">
                <a-select v-model="queryParam.sendStatus" placeholder='请选择' allowClear>
                  <a-select-option value="1">未领取</a-select-option>
                  <a-select-option value="2">已领取</a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
          <a-col :md="!advanced && 8 || 24" :sm="24">
            <a-button v-action:query type="primary" @click="$refs.table.refresh(true)">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!--  #####################操作###################  -->
    <div class="table-operator">
      <!--<a-button v-action:query type="primary" @click="handleAdd">批量核销</a-button>-->
      <a-button v-action:query icon="rollback" @click="handleGoBack">返回</a-button>
    </div>
    <!--  #####################操作###################  -->

    <!--  #####################表格###################  -->
    <s-table
      ref="table"
      :columns="columns"
      :data="loadData"
      bordered
    >
      <span slot="amount" slot-scope="text, record">
        <b>{{record.transactionId ? '￥' : '' }}{{record.transactionId ? text * 0.01 : text }}</b>
      </span>
      <a-tag slot="status" slot-scope="text, record" :color="text | statusColorFilter">
        {{text | statusFilter}}
      </a-tag>
      <a-tag slot="sendStatus" slot-scope="text, record" :color="text | sendColorFilter">
        {{text | sendFilter}}
      </a-tag>

    </s-table>
    <!--  #####################表格###################  -->

    <!--  #####################打开的页面###################  -->
    <!--<customer-pic-edit ref="createModal" @ok="handleOk"/>-->
    <!--  #####################打开的页面###################  -->
  </div>
</template>

<script>
  import moment from 'moment'
  import { STable } from '@/components'
  import { selectPage } from '@/api/shop/trade'

  const statusMap = {
    0: {
      status: '',
      text: '未支付'
    },
    1: {
      status: 'cyan',
      text: '已支付'
    }
  }
  const notityMap = {
    1: {
      status: 'red',
      text: '未领取'
    },
    2: {
      status: '#2db7f5',
      text: '已领取'
    },
  }

  export default {
    name: 'menuList',
    components: {
      STable
    },
    props: {
      record: {
        type: [Object, String],
        default: ''
      }
    },
    data () {
      return {
        treeData: [],
        // 高级搜索 展开/关闭
        advanced: false,
        // 查询参数
        queryParam: {},
        // 表头
        columns: [
          {
            title: '商品名称',
            dataIndex: 'productName'
          },
          /*{
            title: '商品ID',
            dataIndex: 'productNo'
          },*/
          {
            title: '用户昵称',
            dataIndex: 'nickName'
          },
          {
            title: '客户订单号',
            dataIndex: 'outTradeNo'
          },
          {
            title: '金额',
            dataIndex: 'price',
            scopedSlots: { customRender: 'amount' }
          },
          {
            title: '订单创建时间',
            dataIndex: 'createdTime'
          },
          {
            title: '支付状态',
            dataIndex: 'status',
            scopedSlots: { customRender: 'status' }
          },
          {
            title: '领取状态',
            dataIndex: 'sendStatus',
            scopedSlots: { customRender: 'sendStatus' }
          },
          {
            title: '交易单号',
            dataIndex: 'transactionId'
          },
          {
            title: '操作',
            dataIndex: 'action',
            width: '150px',
            scopedSlots: { customRender: 'action' }
          }
        ],
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          parameter.miniOpenid = this.record.miniOpenid
          return selectPage(Object.assign(parameter, this.queryParam))
            .then(res => {
              return res.result.pageInfo
            })
        }
      }
    },
    created() {

    },
    filters: {
      statusFilter (status) {
        return statusMap[status].text
      },
      statusColorFilter (status) {
        return statusMap[status].status
      },
      sendFilter (status) {
        return notityMap[status].text
      },
      sendColorFilter (status) {
        return notityMap[status].status
      }
    },
    methods: {
      handleAdd () {
        this.$refs.createModal.add(this.record.id)
      },
      handleEdit (record) {
        this.$refs.createModal.edit(record)
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      handleGoBack () {
        this.$emit('onGoBack')
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      resetSearchForm () {
        this.queryParam = {
          date: moment(new Date())
        }
      }
    }
  }
</script>
